﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FindPrescription.aspx.cs" Inherits="HZ.Supervise.Web.Common.FindPrescription" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>选择处方单</title>
    <link rel="stylesheet" type="text/css" href="../style/global.css" />

    <script type="text/javascript" src="../scripts/jquery.js"></script>

    <script type="text/javascript" src="../scripts/mainlistSelect.js"></script>

    <script type="text/javascript" src="../scripts/Common.js"></script>

    <script type="text/javascript" src="../scripts/global.js"></script>
    <script type="text/javascript" src="../Scripts/My97DatePicker/WdatePicker.js"></script>

    <script type="text/javascript" language="javascript">
        function addAreaInfo() {
            var AreaInfo;
            AreaInfo = document.getElementById("PrescriptionId").value + "|" + document.getElementById("PrescriptionName").value + "|" + document.getElementById("PSubsidiesAmount").value + "|" + document.getElementById("PSbsidyAmount").value + "|" + document.getElementById("PEssentialDrugsAmount").value;
            opener.insertAreaInfo(AreaInfo);
            window.close();
        }

        function chkAllCompany() {
            CheckBoxList = document.getElementsByName("chkArea");
            for (var i = 0; i < CheckBoxList.length; i++) {
                CheckBoxList[i].checked = true;
            }
        }


        function insertCompanyInfo() {

            if (!checkSelectedItems('gvwAreaList', '请至少选择一项！')) {
                return false;
            }

            CheckBoxList = document.getElementsByName("chkArea");
            var resultValue = "";
            var hosNames = "";
            var hosIDs = "";
            var PSubsidiesAmount = "";
            var PSbsidyAmount = "";
            var PEssentialDrugsAmount = "";
            for (var i = 0; i < CheckBoxList.length; i++) {
                if (CheckBoxList[i].checked) {
                    resultValue = CheckBoxList[i].value;
                    tempId = resultValue.split("|")[0];
                    tempName = resultValue.split("|")[1];
                    tempPSubsidiesAmount = resultValue.split("|")[2];
                    tempPSbsidyAmount = resultValue.split("|")[3];
                    tempPEssentialDrugsAmount = resultValue.split("|")[4];
                    hosIDs = hosIDs + tempId + ",";
                    hosNames = hosNames + tempName + ",";
                    hosPSubsidiesAmounts = tempPSubsidiesAmount + PSubsidiesAmount + ",";
                    hosPSbsidyAmounts = tempPSbsidyAmount + PSbsidyAmount + ",";
                    hosPEssentialDrugsAmounts = tempPEssentialDrugsAmount + PEssentialDrugsAmount+","
                }
            }

            var listbox = document.getElementById("ListPrescription");
            var hosID = document.getElementById("PrescriptionId");
            var hosName = document.getElementById("PrescriptionName");
            var hosPSubsidiesAmount = document.getElementById("PSubsidiesAmount");
            var hosPSbsidyAmount = document.getElementById("PSbsidyAmount");
            var hosPEssentialDrugsAmount = document.getElementById("PEssentialDrugsAmount");
            var arrayName = hosNames.split(',');
            var arrayID = hosIDs.split(',');
            var arrayPSubsidiesAmount = hosPSubsidiesAmounts.split(',');
            var arrayPSbsidyAmount = hosPSubsidiesAmounts.split(',');
            var arrayPEssentialDrugsAmount = hosPEssentialDrugsAmounts.split(',');
            var isUnique = true;
            var temp;
            for (m = 0; m < arrayID.length; m++) {
                for (n = 0; n < listbox.options.length; n++) {
                    if (arrayID[m] == listbox.options[n].value) {
                        isUnique = false;
                        temp = arrayName[m];
                        break;
                    }
                }
            }

            if (isUnique == true) {
                for (var i = 0; i < arrayName.length; i++) {
                    if (!isNull(arrayName[i])) {
                        var listItem = document.createElement("OPTION");
                        listItem.text = arrayName[i];
                        listItem.value = arrayID[i];
                        listbox.add(listItem);
                    }
                }
            }
            else {
                alert("处方单" + temp + "已经存在！");
                return;
            }
            hosID.value = "";
            hosName.value = "";
            for (j = listbox.options.length - 1; j >= 0; j--) {
                hosID.value += listbox[j].value + ",";
                hosName.value += listbox[j].text + ",";
                $("#PSubsidiesAmount").attr("value", hosPSubsidiesAmounts);
                $("#PSbsidyAmount").attr("value", hosPSbsidyAmounts);
                $("#PEssentialDrugsAmounts").attr("value", hosPEssentialDrugsAmounts);
            }
        }

        function deleteCompany() {
            if (!isNull(checkSelected())) {
                var info = checkSelected();
                alert(info);
                return;
            }
            var listbox = document.getElementById("ListPrescription");
            var companyID = document.getElementById("PrescriptionId");
            var companyName = document.getElementById("PrescriptionName");
            var hosPSubsidiesAmount = document.getElementById("PSubsidiesAmount");
            var hosPSbsidyAmount = document.getElementById("PSbsidyAmount");
            var PEssentialDrugsAmount = document.getElementById("PEssentialDrugsAmount"); ;
            companyID.value = "";
            companyName.value = "";
            hosPSubsidiesAmount.value = "";
            hosPSbsidyAmount.value = "";
            hosPEssentialDrugsAmount.value = "";
            var selectindex = listbox.selectedIndex;
            listbox.remove(selectindex);

            for (j = listbox.options.length - 1; j >= 0; j--) {
                companyID.value = companyID.value + listbox[j].value + ",";
                companyName.value = companyName.value + listbox[j].text + ",";
                $("#PSubsidiesAmount").attr("value", hosPSubsidiesAmounts);
                $("#PSbsidyAmount").attr("value", hosPSbsidyAmounts);
                $("#PEssentialDrugsAmount").attr("value", hosPEssentialDrugsAmounts);
            }
        }

        function checkSelected() {
            var info;
            var listbox = document.getElementById("ListPrescription");
            var selectindex = listbox.selectedIndex;
            if (selectindex < 0) {
                info = "请选择要删除的处方单！";
                return info;
            }
            return "";
        }

        function isNull(str) {
            var re = /^[ \s]*$/;
            return re.test(str);
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <table class="querylist">
        <tr>
            <td colspan="3">
                选择处方单：
            </td>
        </tr>
          <tr>
            <td>
                
                处方单名称：<asp:TextBox ID="txtproductName" runat="server"></asp:TextBox>
                
            </td>
            <td>
                                <asp:Label ID="labPlanTime" runat="server" Text="发放时间："></asp:Label>
                                <asp:TextBox ID="txtStratTime" runat="server" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true})"
                                    Width="63px"></asp:TextBox>-<asp:TextBox ID="txtEndTime" runat="server" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',readOnly:true})"
                                        Width="63px"></asp:TextBox>
              </td>
            <td>
                                
        <hz:HzButton ID="HzButton1" runat="server" Text="查询"
            CssClass="btn" OperateType="编辑" onclick="HzButton1_Click"  />
                                
              </td>
        </tr>
        <tr>
            <td colspan="3">
                <asp:GridView ID="gvwAreaList" runat="server" CssClass="mainlist" AutoGenerateColumns="False"
                    DataKeyNames="PrescriptionId" EmptyDataText="暂无符合条件的数据！">
                    <Columns>
                        <asp:TemplateField>
                            <HeaderTemplate>
                                <input id="chkAllArea" name="chkAllArea" type="checkbox" onclick="SelectAllCheckboxes(this,'gvwAreaList','chkAllArea');" />
                            </HeaderTemplate>
                            <ItemTemplate>
                                <input id="chkArea" name="chkArea" type="checkbox" onclick="chkChecked(this,'gvwAreaList','chkAllArea');"
                                    value='<%# Eval("PrescriptionId") %>|<%# Eval("PrescriptionName") %>|<%# Eval("PSubsidiesAmount") %>|<%# Eval("PSbsidyAmount") %>|<%# Eval("PtotalAmount") %> '> </input>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="处方单名称">
                            <ItemTemplate>
                                <asp:Label ID="lblAreaName" runat="server" Text='<%# Eval("PrescriptionName") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="Paddtime" HeaderText="开方时间"  ReadOnly="True"/> 
                        <asp:BoundField DataField="PSubsidiesAmount" HeaderText="应补贴金额"  ReadOnly="True"/>
                       <asp:BoundField DataField="PSbsidyAmount" HeaderText="已补贴金额"  ReadOnly="True"/>
                    </Columns>
                </asp:GridView>
                <webdiyer:AspNetPager ID="AspNetPager1" runat="server" CustomInfoHTML="" CustomInfoStyle="display:none"
                    NumericButtonCount="5" OnPageChanged="AspNetPager1_PageChanged" ReverseUrlPageIndex="false"
                    ShowDisabledButtons="False" ShowFirstLast="False" ShowMoreButtons="false" ShowPageSizeBox="false"
                    ShowPrevNext="False">
                </webdiyer:AspNetPager>
                <input id="PrescriptionId" type="hidden" name="HosId" runat="server" />
                <input id="PrescriptionName" type="hidden" name="HosName" runat="server" />
                <input id="PSubsidiesAmount" type="hidden" name="HosPSubsidiesAmount" runat="server" />
                <input id="PSbsidyAmount" type="hidden" name="HosPSbsidyAmount" runat="server" />
                <input id="PEssentialDrugsAmount" type="hidden" name="HosPSbsidyAmount" runat="server" />
            </td>
        </tr>
        <tr>
            <td>
                &nbsp;
                    <input type="button" id="btnIn" value="加入" class="btn" onclick="insertCompanyInfo();" />
                    </td>
                    <td> <input type="button" id="btnOut" value="删除" class="btn" onclick="deleteCompany();" /></td>
                    <td> <input type="button" id="btnOk" value="确认" class="btn" onclick="return addAreaInfo();" /></td>
            
        </tr>
        <tr>
        <td colspan="3">已选择的处方单：
            </td>
        </tr>
        <tr>
        <td colspan="3">
                <asp:ListBox ID="ListPrescription" runat="server" Height="300px" Width="100%"></asp:ListBox>
                </td>
        
        </tr>
    </table>
    </form>
</body>
</html>

